from django.db import models
# Create your models here.


class User(models.Model):
    username = models.CharField(max_length=100, blank=True, null=True)
    email = models.CharField(max_length=100, blank=True, null=True)
    phone = models.CharField(max_length=100, blank=True, null=True)
    password = models.CharField(max_length=100)
    img = models.CharField(max_length=100, default='http://127.0.0.1:8000/uploads/image/6.jpg')

    def __str__(self):
        return self.username

    class Meta:
        db_table = 'user'


class Cate(models.Model):
    name = models.CharField(max_length=100, verbose_name='分类')

    class Meta:
        db_table = 'cate'


class Shoes(models.Model):
    name = models.CharField(max_length=100, verbose_name='名称')
    price = models.CharField(max_length=100, verbose_name='价格')
    image = models.CharField(max_length=100, verbose_name='图片')
    desc = models.CharField(max_length=100, verbose_name='描述', blank=True, null=True)
    cate = models.ForeignKey(Cate, on_delete=models.CASCADE, verbose_name='分类')

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'shoes'


class Cart(models.Model):
    shoes = models.ForeignKey(Shoes, on_delete=models.CASCADE, verbose_name='商品')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    count = models.IntegerField(default=1, verbose_name='数量')

    class Meta:
        db_table = 'cart'


class Like(models.Model):
    shoes = models.ForeignKey(Shoes, on_delete=models.CASCADE, verbose_name='商品')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')

    class Meta:
        db_table = 'like'


class Score(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    score = models.IntegerField(default=0, verbose_name='积分')

    class Meta:
        db_table = 'score'


class Address(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    name = models.CharField(max_length=100, verbose_name='收货人')
    phone = models.CharField(max_length=100, verbose_name='手机号')
    province = models.CharField(max_length=100, verbose_name='省份')
    city = models.CharField(max_length=100, verbose_name='城市')
    address = models.CharField(max_length=100, verbose_name='详细地址')
    remark = models.CharField(max_length=100, verbose_name='备注', blank=True, null=True)

    class Meta:
        db_table = 'address'


class Type(models.Model):
    name = models.CharField(max_length=100, verbose_name='类型')

    class Meta:
        db_table = 'type'


class Order(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='用户')
    type = models.ForeignKey(Type, on_delete=models.CASCADE, verbose_name='类型', blank=True, null=True)
    order_id = models.CharField(max_length=100, verbose_name='订单号')
    pay_time = models.DateTimeField(auto_now_add=True, verbose_name='支付时间', blank=True, null=True)
    pay_status = models.CharField(max_length=100, verbose_name='支付状态', choices=(('1', '待支付'), ('2', '已支付'), ('3', '已取消')), default=1)
    pay_total = models.CharField(max_length=100, verbose_name='订单总额')
    pay_money = models.CharField(max_length=100, verbose_name='支付金额')
    score = models.IntegerField( verbose_name='积分', blank=True, null=True, default=10)
    pay_num = models.CharField(max_length=30, verbose_name='流水号', blank=True, null=True)

    class Meta:
        db_table = 'order'


class OrderDeta(models.Model):
    order = models.ForeignKey(Order, on_delete=models.CASCADE, verbose_name='订单')
    shoes_id = models.CharField(max_length=100, verbose_name='商品id')
    shoes_price = models.CharField(max_length=100, verbose_name='商品价格')
    shoes_img = models.CharField(max_length=200, verbose_name='商品图片')
    shoes_name = models.CharField(max_length=100, verbose_name='商品名称')

    class Meta:
        db_table = 'order_deta'


